import jdk.swing.interop.SwingInterOpUtils;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-07-05
 * Time: 22:42
 */
//https://leetcode.cn/problems/invert-binary-tree/
    //给你一棵二叉树的根节点 root ，翻转这棵二叉树，并返回其根节点。
 //Definition for a binary tree node.
class TreeNode {
      int val;
      public TreeNode left;
      public TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
}
public class Test {
    static TreeNode node;
    public static TreeNode invertTree(TreeNode root) {
        if(root==null){
            return root;
        }
        invertTree(root.left);
        invertTree(root.right);
        node=root.left;
        root.left=root.right;
        root.right=node;
        return root;
    }
    public static void main(String[] args) {
        TreeNode A1=new TreeNode(1);
        TreeNode A2=new TreeNode(2);
        TreeNode A3=new TreeNode(3);
        TreeNode A4=new TreeNode(4);
        TreeNode A5=new TreeNode(5);
        TreeNode A6=new TreeNode(6);
        TreeNode A7=new TreeNode(7);
        A1.left=A2;A1.right=A3;
        A2.left=A4;A2.right=A5;
        A3.left=A6;A3.right=A7;
        A1=invertTree(A1);
        System.out.println();
    }
}
